const query=require('../util/db')

//增
const getzeng=async(params)=>{
    const {username,password,nickname, age, phone }=params
     let sql = `insert into user (username,password,nickname,age,phone) value ('${username}','${password}','${nickname}','${age}','${phone}')`
     let res=await query(sql)
     if(res.affectedRows==1){
     return true
     }  
     else{
        return false
     }
} 

//删
const getshan = async(parmas) => {
    const { id } = parmas
    let sql = `delete from user where id=${id}`
    let res = await query(sql)
    if (res.affectedRows == 1) {
        return true
    } else {
        return false
    }
}

//改
const getgai = async(parmas) => {
        const { username, nickname,password, age, phone, id } = parmas
        let sql = `update user set username='${username}',nickname='${nickname}',age='${age}',password='${password}',phone='${phone}' where id=${id}`
        let res = await query(sql)
        if (res.affectedRows == 1) {
            return true
        } else {
            return false
        }
    }


//查
const getser=async(params)=>{
   const {username,password,nickname, age, phone }=params
   let sql=`select * from user where username='${username}' and password='${password}' and nickname='${nickname}' and age='${age}' and phone='${phone}'`
   let res=await query(sql)
   if(res.length>0){
    return res[0]
   }else{
    return false
   }
}

module.exports={
    getzeng,
    getshan,
    getgai,
    getser
}